/*
 *         (C) COPYRIGHT NBI Limited
 *              ALL RIGHT RESERVED
 *
 * File        : fastflow/graph/model.h
 * Authors     : dzhang
 * Create Time : 2021/09/04 17:24:57
 * Description :
 *
 */

#ifndef __FASTFLOW_GRAPH_MODEL_H___
#define __FASTFLOW_GRAPH_MODEL_H___

#include <list>
#include <map>
#include <memory>

#include "fastflow/core/status.h"
#include "fastflow/graph/graph.h"
#include "fastflow/graph/onnx_proto_helper.h"

namespace fastflow {

typedef std::unordered_map<std::string, std::string> ModelMetaData;
using IFastFlowOpSchemaRegistryList = std::list<std::shared_ptr<IFastFlowOpSchemaCollection>>;

class Model {
public:
    static constexpr Version kNoVersion = INT64_MAX;

public:
    Model(const std::string& graph_name, bool is_onnx_domain_only, const ModelMetaData& model_metadata,
          const IFastFlowOpSchemaRegistryList local_registries,
          const std::unordered_map<std::string, int>& domain_to_version,
          const std::vector<ONNX_NAMESPACE::FunctionProto>& model_functions);

    Model(const ModelProto& model_proto, const IFastFlowOpSchemaRegistryList* local_registries = nullptr);

    Model(std::unique_ptr<ModelProto> model_proto, const IFastFlowOpSchemaRegistryList* local_registries = nullptr);
    // Get model's main graph.
    Graph& MainGraph() noexcept;
    const Graph& MainGraph() const noexcept;

    // Get model's serialization proto data.
    ONNX_NAMESPACE::ModelProto ToProto();

    // Get model's IR version.
    // Return <kNoVersion> if not specified.
    Version IrVersion() const;

private:
    Model();

private:
    // Model data.
    std::unique_ptr<ONNX_NAMESPACE::ModelProto> model_proto_;

    // This is a duplication of <model_proto_.metadata_props()>.
    // It gives better accessibility.
    ModelMetaData model_metadata_;

    // Main graph of the model.
    std::unique_ptr<Graph> graph_;
};

}  // namespace fastflow

#endif  // __FASTFLOW_GRAPH_MODEL_H___